package com.dlc.shop.systemtest.api.order;

import cn.hutool.core.bean.BeanUtil;
import com.dlc.shop.bean.app.dto.OrderNumbersDto;
import com.dlc.shop.bean.app.dto.ShopCartOrderMergerDto;
import com.dlc.shop.bean.app.param.OrderParam;
import com.dlc.shop.bean.app.param.OrderPayInfoParam;
import com.dlc.shop.bean.app.param.SubmitOrderParam;
import com.dlc.shop.bean.model.Order;
import com.dlc.shop.bean.vo.OrderDetailVO;
import com.dlc.shop.systemtest.constants.Constant;
import com.dlc.shop.systemtest.util.HttpUtil;

import java.util.Objects;

/**
 * @author lanhai
 */
public class OrderApi {
    public static ShopCartOrderMergerDto confirm(OrderParam orderParam){
        String uri = Constant.API_URL+"/p/order/confirm";
        return HttpUtil.post(uri,orderParam,ShopCartOrderMergerDto.class,true);
    }

    public static OrderNumbersDto submit(SubmitOrderParam submitOrderParam){
        String uri = Constant.API_URL+"/p/order/submit";
        Object post = HttpUtil.post(uri, submitOrderParam,Object.class,true);
        OrderNumbersDto orderNumbersDto = BeanUtil.copyProperties(post, OrderNumbersDto.class);
        return orderNumbersDto;
    }


    public static OrderPayInfoParam getOrderPayInfo(String orderNumbers){
        String uri = Constant.API_URL+"/p/order/getOrderPayInfoByOrderNumber?orderNumbers="+orderNumbers;
        return HttpUtil.get(uri,OrderPayInfoParam.class);
    }

    /**
     * 商家修改订单价格
     * @param order
     */
    public static void changeAmount(Order order){
        String url = Constant.SHOP_URL + "/order/order/changeAmount";
        HttpUtil.put(url, order);
    }

    /**
     * 根据订单号获取订单信息
     * @param orderNumber
     * @return
     */
    public static Order getOrderByOrderNumber(String orderNumber, Long shopId){
        String url = Constant.SHOP_URL + "/order/order/orderInfo"+"/" +orderNumber;
        return HttpUtil.get(url, Order.class, Objects.equals(shopId, 1L) ? true : false);
    }

    public static Order getOrderByOrderNumber(String orderNumber){
        String url = Constant.SHOP_URL + "/order/order/orderInfo"+"/" +orderNumber;
        return HttpUtil.get(url, Order.class);
    }

    /**
     * 订单结算
     * @param order
     */
    public static void  orderCommissionSettlement(Order order){
        String url = Constant.SHOP_URL + "/order/order/orderCommissionSettlement";
        HttpUtil.post(url, order);
    }
    public static  com.dlc.shop.delivery.common.param.OrderParam getOrderDetailInfo(String orderNumber) {
        String uri = Constant.PLATFORM_URL+"/platform/orderDelivery/orderInfo/" + orderNumber;
        return HttpUtil.get(uri, com.dlc.shop.delivery.common.param.OrderParam.class);
    }

    /**
     * 获取结算明细
     */
    public static OrderDetailVO getOrderItemDetail(String orderNumber, String refundSn) {
        String url = Constant.SHOP_URL + "/multishop/order_item/get_order_detail?orderNumber=" + orderNumber + "&refundSn=" + refundSn;
        return HttpUtil.get(url, OrderDetailVO.class);
    }
}
